

//Install packages and schemes if needed
ssc install estout
ssc install coefplot

ssc install blindschemes


//Set working directory first
use "CES 1988-2019 Data.dta", clear

/////////////////////////////////////////Figure 4 - NDP Therm and Racial Minorities Therm

eststo clear
eststo model1988: reg ndptherm rmtherm   if electionyear == 1988 [pweight=nationalweight]
eststo model1993: reg ndptherm rmtherm  if electionyear == 1993 [pweight=nationalweight]
eststo model1997: reg ndptherm rmtherm   if electionyear == 1997 [pweight=nationalweight]
eststo model2004: reg ndptherm rmtherm   if electionyear == 2004 [pweight=nationalweight]
eststo model2006: reg ndptherm rmtherm   if electionyear == 2006 [pweight=nationalweight]
eststo model2008: reg ndptherm rmtherm   if electionyear == 2008 [pweight=nationalweight]
eststo model2011: reg ndptherm rmtherm   if electionyear == 2011 [pweight=nationalweight]
eststo model2015phone: reg ndptherm rmtherm   if electionyear == 2015 & mode==0 [pweight=nationalweight] 
eststo model2015online: reg ndptherm rmtherm   if electionyear == 2015  & mode==1 [pweight=nationalweight]
eststo model2019online: reg ndptherm rmtherm   if electionyear == 2019 & mode==1 [pweight=nationalweight] 


coefplot  model1988 model1993 model1997  model2004 model2006 model2008 model2011  model2015phone model2015online model2019online   ///
, nodraw drop(_cons) vertical keep (rmtherm) asequation swapnames legend(off)   scheme (plottig)  ytitle("NDP / Racial Therm Coef") title("Bivariate")  ///
xlabel(.55 "1988" 1.65 "1993" 2.75 "1997" 3.85 "2004" 4.95 "2006" 6.05 "2008" 7.15 "2011" 8.25 "2015 Phone" 9.35 "2015 Online" 10.45 "2019 Online"  , angle(45))
graph save Graph "Bivariate, modes.gph", replace

esttab using "Table4B - RacialTherm Bivariate.rtf", se r2 ar2  b(a2) compress  modelwidth(5) replace nobaselevels label rename (rmtherm RacialTherm) ///
title(Table 4B: Bivariate Models (Figure 4, Top Panel)) nonumbers ///
mtitles("1988"	"1993"	"1997"	"2004"	"2006"	"2008"	"2011"	"2015 Phone" "2015 Online"  "2019 Online")


eststo clear
eststo model1988controls: reg ndptherm rmtherm   ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic   if electionyear == 1988 [pweight=nationalweight]
eststo model1993controls: reg ndptherm rmtherm   ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic  if electionyear == 1993 [pweight=nationalweight]
eststo model1997controls: reg ndptherm rmtherm   ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic  if electionyear == 1997 [pweight=nationalweight]
eststo model2004controls: reg ndptherm rmtherm   ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic  if electionyear == 2004 [pweight=nationalweight]
eststo model2006controls: reg ndptherm rmtherm   ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic  if electionyear == 2006 [pweight=nationalweight]
eststo model2008controls: reg ndptherm rmtherm   ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic   if electionyear == 2008 [pweight=nationalweight]
eststo model2011controls: reg ndptherm rmtherm   ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic   if electionyear == 2011 [pweight=nationalweight]
eststo model2015controlsphone: reg ndptherm rmtherm ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic    if electionyear == 2015 & mode==0 [pweight=nationalweight] 
eststo model2015controlsonline: reg ndptherm rmtherm ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic    if electionyear == 2015  & mode==1 [pweight=nationalweight]
eststo model2019controlsonline: reg ndptherm rmtherm ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic    if electionyear == 2019 & mode==1 [pweight=nationalweight] 

coefplot    model1988controls model1993controls model1997controls  model2004controls model2006controls model2008controls model2011controls         model2015controlsphone model2015controlsonline  model2019controlsonline  ///
, nodraw drop(_cons) vertical keep (rmtherm) asequation swapnames legend(off)   scheme (plottig)  ytitle("NDP / Racial Therm Coef") title("Multivariate") ylabel(0(.05)0.2) ///
xlabel(.55 "1988" 1.65 "1993" 2.75 "1997" 3.85 "2004" 4.95 "2006" 6.05 "2008" 7.15 "2011" 8.25 "2015 Phone" 9.35 "2015 Online" 10.45 "2019 Online"  , angle(45))
graph save Graph "Controls, modes.gph", replace


graph combine "Bivariate, modes.gph" "Controls, modes.gph",  imargin(zero) scheme(plottig)  commonscheme cols(1) ysize(6)  play("Figure 4 - racial therm and ndp.grec") 
graph save  "Figure 4 - Racial Spillover to the Party", replace
graph export "Figure 4 - Racial Spillover to the Party.pdf", replace

esttab using "Table5B - RacialTherm Multivariate.rtf", replace se r2 ar2  b(2) compress modelwidth(5) nobaselevels ///
label order(rmtherm ftherm age educ income woman 1.partisanship 2.partisanship 3.partisanship 4.partisanship 5.partisanship  ///
 1.prov 2.prov 3.prov 4.prov 5.prov 6.prov 7.prov 8.prov 9.prov 10.prov ///
 1.ces_ethnic 2.ces_ethnic 3.ces_ethnic 4.ces_ethnic 5.ces_ethnic 6.ces_ethnic 7.ces_ethnic _cons) ///
varlabels(rmtherm RacialTherm ftherm FemTherm age Age educ Education income Income woman Woman  ///
1.partisanship Conservative 2.partisanship Liberal 3.partisanship NDP 4.partisanship BQ 5.partisanship OtherPID  _cons Intercept) ///
title(Table 5B: Multivariate Models (Figure 4, Bottom Panel)) nonumbers ///
mtitles("1988"	"1993"	"1997"	"2004"	"2006"	"2008"	"2011"	"2015 Phone" "2015 Online"  "2019 Online")

//Check if statistically significant, reported in text
eststo clear
eststo model1988controls: reg ndptherm rmtherm   ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic  if electionyear == 1988 [aweight=nationalweight]
eststo model1993controls: reg ndptherm rmtherm   ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic  if electionyear == 1993 [aweight=nationalweight]
eststo model1997controls: reg ndptherm rmtherm   ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic  if electionyear == 1997 [aweight=nationalweight]
eststo model2004controls: reg ndptherm rmtherm   ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic  if electionyear == 2004 [aweight=nationalweight]
eststo model2006controls: reg ndptherm rmtherm   ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic  if electionyear == 2006 [aweight=nationalweight]
eststo model2008controls: reg ndptherm rmtherm   ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic  if electionyear == 2008 [aweight=nationalweight]
eststo model2011controls: reg ndptherm rmtherm   ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic  if electionyear == 2011 [aweight=nationalweight]
eststo model2015controlsphone: reg ndptherm rmtherm ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic    if electionyear == 2015 & mode==0 [aweight=nationalweight] 
eststo model2015controlsonline: reg ndptherm rmtherm ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic    if electionyear == 2015  & mode==1 [aweight=nationalweight]
eststo model2019controlsonline: reg ndptherm rmtherm ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic    if electionyear == 2019 & mode==1 [aweight=nationalweight] 

suest  model1988controls model1993controls model1997controls  model2004controls model2006controls model2008controls model2011controls model2015controlsphone model2015controlsonline model2019controlsonline


test [model1988controls_mean ]rmtherm=[model2019controlsonline_mean ]rmtherm
test [model1993controls_mean ]rmtherm=[model2019controlsonline_mean ]rmtherm
test [model1997controls_mean ]rmtherm=[model2019controlsonline_mean ]rmtherm
test [model2004controls_mean ]rmtherm=[model2019controlsonline_mean ]rmtherm
test [model2006controls_mean ]rmtherm=[model2019controlsonline_mean ]rmtherm
test [model2008controls_mean ]rmtherm=[model2019controlsonline_mean ]rmtherm
test [model2011controls_mean ]rmtherm=[model2019controlsonline_mean ]rmtherm
test [model2015controlsphone_mean ]rmtherm=[model2019controlsonline_mean ]rmtherm
test [model2015controlsonline_mean ]rmtherm=[model2019controlsonline_mean ]rmtherm

test [model2011controls_mean ]rmtherm=[model2015controlsphone_mean ]rmtherm
test [model2011controls_mean ]rmtherm=[model2015controlsonline_mean ]rmtherm
  

///////////////////////////////////////// Figure 5 - NDP Therm and Do For Minorities

eststo clear
eststo model1993: reg ndptherm rmDoMore   if electionyear == 1993 [pweight=nationalweight]
eststo model2000: reg ndptherm rmDoMore   if electionyear == 2000 [pweight=nationalweight]
eststo model2004: reg ndptherm rmDoMore   if electionyear == 2004 [pweight=nationalweight]
eststo model2008: reg ndptherm rmDoMore   if electionyear == 2008  [pweight=nationalweight]
eststo model2011: reg ndptherm rmDoMore   if electionyear == 2011  [pweight=nationalweight]
eststo model2015phone: reg ndptherm rmDoMore   if electionyear == 2015 & mode==0 [pweight=nationalweight]
eststo model2015online: reg ndptherm rmDoMore   if electionyear == 2015 & mode==1 [pweight=nationalweight]
eststo model2019phone: reg ndptherm rmDoMore   if electionyear == 2019 & mode==0 [pweight=nationalweight]
eststo model2019online: reg ndptherm rmDoMore   if electionyear == 2019 & mode==1 [pweight=nationalweight]

coefplot    model1993  model2000 model2004 model2008 model2011  model2015phone model2015online  model2019phone model2019online  ///
, nodraw drop(_cons)keep (rmDoMore) vertical  asequation swapnames legend(off) scheme (plotplainblind) name(bivariate, replace)  ///
title ("Bivariate") ytitle("NDP / Do For Coef") xlabel(, angle(45)) ///
xlabel(.55 "1993" 1.65 "2000" 2.75 "2004" 3.85 "2008" 4.95 "2011" 6.05 "2015 Phone" 7.15 "2015 Online" 8.25 "2019 Phone" 9.35 "2019 Online" )
  
esttab using "Table6B - DoFor Bivariate.rtf", se r2 ar2  b(a2) compress  modelwidth(5) replace nobaselevels label rename (rmDoMore "Do For Minorities") ///
title(Table 6B: Bivariate Models (Figure 5, Top Panel)) nonumbers ///
mtitles("1993"		"2000"	"2004"	"2008"	"2011"	"2015 Phone" "2015 Online"	"2019 Phone"	"2019 Online")

/////With Controls
eststo clear
eststo model1993controls: reg ndptherm rmDoMore   ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic  if electionyear == 1993 [pweight=nationalweight]
eststo model2000controls: reg ndptherm rmDoMore   ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic  if electionyear == 2000  [pweight=nationalweight]
eststo model2004controls: reg ndptherm rmDoMore   ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic  if electionyear == 2004  [pweight=nationalweight]
eststo model2008controls: reg ndptherm rmDoMore   ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic  if electionyear == 2008  [pweight=nationalweight]
eststo model2011controls: reg ndptherm rmDoMore   ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic  if electionyear == 2011  [pweight=nationalweight]
eststo model2015phonecontrols: reg ndptherm rmDoMore   ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic  if electionyear == 2015 & mode==0 [pweight=nationalweight]
eststo model2015onlinecontrols: reg ndptherm rmDoMore   ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic  if electionyear == 2015 & mode==1 [pweight=nationalweight]
eststo model2019phonecontrols: reg ndptherm rmDoMore   ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic  if electionyear == 2019 & mode==0 [pweight=nationalweight]
eststo model2019onlinecontrols: reg ndptherm rmDoMore   ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic  if electionyear == 2019 & mode==1 [pweight=nationalweight]
    
coefplot     model1993controls  model2000controls model2004controls model2008controls model2011controls model2015phonecontrols model2015onlinecontrols  model2019phonecontrols model2019onlinecontrols  ///
, nodraw drop(_cons)keep (rmDoMore) vertical  asequation swapnames legend(off) scheme (plotplainblind) name(multivariate, replace)   ///
title ("Multivariate") ytitle("NDP / Do For Coef") xlabel(, angle(45)) ///
xlabel(.55 "1993" 1.65 "2000" 2.75 "2004" 3.85 "2008" 4.95 "2011" 6.05 "2015 Phone" 7.15 "2015 Online" 8.25 "2019 Phone" 9.35 "2019 Online" )

graph combine bivariate multivariate,  imargin(zero) scheme(plottig)  commonscheme xcommon cols(1) ysize(6) play("Figure 5 - do for minorities and ndp.grec") 
graph save Graph "Figure 5 - Do For Minorities", replace
graph export "Figure 5 - Do For Minorities.pdf", replace


esttab using "Table7B - DoFor Multivariate.rtf", replace se r2 ar2  b(2) compress modelwidth(5) nobaselevels ///
label order(rmDoMore ftherm age educ income woman 1.partisanship 2.partisanship 3.partisanship 4.partisanship 5.partisanship  ///
 1.prov 2.prov 3.prov 4.prov 5.prov 6.prov 7.prov 8.prov 9.prov 10.prov ///
 1.ces_ethnic 2.ces_ethnic 3.ces_ethnic 4.ces_ethnic 5.ces_ethnic 6.ces_ethnic 7.ces_ethnic _cons) ///
varlabels(rmDoMore DoForMinorities ftherm FemTherm age Age educ Education income Income woman Woman  ///
1.partisanship Conservative 2.partisanship Liberal 3.partisanship NDP 4.partisanship BQ 5.partisanship OtherPID  _cons Intercept) ///
title(Table 7B: Multivariate Models (Figure 5, Bottom Panel)) nonumbers ///
mtitles("1993"	"1997"	"2000"	"2004"	"2008"	"2011"	"2015 Phone"	"2015 Online"	"2019 Phone"	"2019 Online") 

 
 //Check if statistically signficant, discussed in text
eststo model2015phonecontrols: reg ndptherm rmDoMore   ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic  if electionyear == 2015 & mode==0 [aweight=nationalweight]
eststo model2015onlinecontrols: reg ndptherm rmDoMore   ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic  if electionyear == 2015 & mode==1 [aweight=nationalweight]
eststo model2019phonecontrols: reg ndptherm rmDoMore   ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic  if electionyear == 2019 & mode==0 [aweight=nationalweight]
eststo model2019onlinecontrols: reg ndptherm rmDoMore   ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic  if electionyear == 2019 & mode==1 [aweight=nationalweight]
eststo model2008controls: reg ndptherm rmDoMore   ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic  if electionyear == 2008  [aweight=nationalweight]
    
suest  model2015phonecontrols model2015onlinecontrols model2019phonecontrols model2019onlinecontrols model2008controls

test [model2015onlinecontrols_mean ]rmDoMore=[model2019onlinecontrols_mean ]rmDoMore
test [model2015onlinecontrols_mean ]rmDoMore=[model2019phonecontrols_mean ]rmDoMore
test [model2015phonecontrols_mean ]rmDoMore=[model2019onlinecontrols_mean ]rmDoMore
test [model2015phonecontrols_mean ]rmDoMore=[model2019phonecontrols_mean ]rmDoMore
test [model2008controls_mean ]rmDoMore=[model2019phonecontrols_mean ]rmDoMore
test [model2008controls_mean ]rmDoMore=[model2019onlinecontrols_mean ]rmDoMore
  
  
  
  

//////////////////////////////////////////////////////////////////////////// Appendix ///////////////////////////////////////////


///////////////////////////////////////// Figure 3A Conservative Therm and Racial Therm


eststo clear
eststo model1988: reg contherm rmtherm   if electionyear == 1988 [pweight=nationalweight]
eststo model1993: reg contherm rmtherm  if electionyear == 1993 [pweight=nationalweight]
eststo model1997: reg contherm rmtherm   if electionyear == 1997 [pweight=nationalweight]
eststo model2004: reg contherm rmtherm   if electionyear == 2004 [pweight=nationalweight]
eststo model2006: reg contherm rmtherm   if electionyear == 2006 [pweight=nationalweight]
eststo model2008: reg contherm rmtherm   if electionyear == 2008 [pweight=nationalweight]
eststo model2011: reg contherm rmtherm   if electionyear == 2011 [pweight=nationalweight]
eststo model2015phone: reg contherm rmtherm   if electionyear == 2015 & mode==0 [pweight=nationalweight] 
eststo model2015online: reg contherm rmtherm   if electionyear == 2015  & mode==1 [pweight=nationalweight]
eststo model2019online: reg contherm rmtherm   if electionyear == 2019 & mode==1 [pweight=nationalweight] 


coefplot  model1988 model1993 model1997  model2004 model2006 model2008 model2011 model2015online model2015phone model2019online   ///
, nodraw drop(_cons) vertical keep (rmtherm) asequation swapnames legend(off)   scheme (plottig)   title("Bivariate") ytitle("CPC / Racial Therm Coef")  ylabel(-.3(.05)0.2) ///
xlabel(.55 "1988" 1.65 "1993" 2.75 "1997" 3.85 "2004" 4.95 "2006" 6.05 "2008" 7.15 "2011" 8.25 "2015 Phone" 9.35 "2015 Online" 10.45 "2019 Online"  , angle(45))
graph save Graph "BivariateConservative.gph", replace

esttab using "Table4A - RacialTherm Bivariate Con.rtf", replace se r2 ar2  b(2) compress modelwidth(5) nobaselevels ///
label varlabels(rmtherm RacialTherm   _cons Intercept) ///
title(Table 3A: Bivariate Models (Conservative Therm DV)) nonumbers ///
mtitles("1988" "1993"	"1997"	"2004" "2006"	"2008"	"2011"	"2015 Phone" "2015 Online" "2019 Online") 


eststo clear
eststo model1988controls: reg contherm rmtherm   ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic   if electionyear == 1988 [pweight=nationalweight]
eststo model1993controls: reg contherm rmtherm   ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic  if electionyear == 1993 [pweight=nationalweight]
eststo model1997controls: reg contherm rmtherm   ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic  if electionyear == 1997 [pweight=nationalweight]
eststo model2004controls: reg contherm rmtherm   ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic  if electionyear == 2004 [pweight=nationalweight]
eststo model2006controls: reg contherm rmtherm   ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic  if electionyear == 2006 [pweight=nationalweight]
eststo model2008controls: reg contherm rmtherm   ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic   if electionyear == 2008 [pweight=nationalweight]
eststo model2011controls: reg contherm rmtherm   ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic   if electionyear == 2011 [pweight=nationalweight]
eststo model2015controlsphone: reg contherm rmtherm ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic    if electionyear == 2015 & mode==0 [pweight=nationalweight] 
eststo model2015controlsonline: reg contherm rmtherm ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic    if electionyear == 2015  & mode==1 [pweight=nationalweight]
eststo model2019controlsonline: reg contherm rmtherm ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic    if electionyear == 2019 & mode==1 [pweight=nationalweight] 

coefplot    model1988controls model1993controls model1997controls  model2004controls model2006controls model2008controls model2011controls         model2015controlsphone model2015controlsonline  model2019controlsonline  ///
, nodraw drop(_cons) vertical keep (rmtherm) asequation swapnames legend(off)   scheme (plottig)  title("Multivariate") ytitle("CPC / Racial Therm Coef")  ylabel(-.2(.05)0.2)  ///
xlabel(.55 "1988" 1.65 "1993" 2.75 "1997" 3.85 "2004" 4.95 "2006" 6.05 "2008" 7.15 "2011" 8.25 "2015 Phone" 9.35 "2015 Online" 10.45 "2019 Online"  , angle(45))
graph save Graph "ControlsConservative.gph", replace


graph combine "BivariateConservative.gph" "ControlsConservative.gph",  imargin(zero) scheme(plottig)  commonscheme cols(1) ysize(6)   play("Figure 4 - racial therm and ndp.grec") 
graph save  "Figure 3A - Racial Spillover to the Party, Conservative", replace
graph export "Figure 3A - Racial Spillover to the Party, Conservative.pdf", replace

esttab using "Table5A - RacialTherm Multivariate Con.rtf", replace se r2 ar2  b(2) compress modelwidth(5) nobaselevels ///
label order(rmtherm ftherm age educ income woman 1.partisanship 2.partisanship 3.partisanship 4.partisanship 5.partisanship  ///
 1.prov 2.prov 3.prov 4.prov 5.prov 6.prov 7.prov 8.prov 9.prov 10.prov ///
 1.ces_ethnic 2.ces_ethnic 3.ces_ethnic 4.ces_ethnic 5.ces_ethnic 6.ces_ethnic 7.ces_ethnic _cons) ///
varlabels(rmDoMore "Do For Minorities" ftherm FemTherm age Age educ Education income Income woman Woman  ///
1.partisanship Conservative 2.partisanship Liberal 3.partisanship NDP 4.partisanship BQ 5.partisanship OtherPID  _cons Intercept) ///
title(Table 5A: Models with Controls (Conservative Therm DV)) nonumbers ///
mtitles("1988" "1993"	"1997"	"2004" "2006"	"2008"	"2011"	"2015 Phone"	"2015 Online" "2019 Online") 



//Check if statistically significant, just reported in text and letter
eststo clear
eststo model1988controls: reg contherm rmtherm   ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic  if electionyear == 1988 [aweight=nationalweight]
eststo model1993controls: reg contherm rmtherm   ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic  if electionyear == 1993 [aweight=nationalweight]
eststo model1997controls: reg contherm rmtherm   ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic  if electionyear == 1997 [aweight=nationalweight]
eststo model2004controls: reg contherm rmtherm   ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic  if electionyear == 2004 [aweight=nationalweight]
eststo model2006controls: reg contherm rmtherm   ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic  if electionyear == 2006 [aweight=nationalweight]
eststo model2008controls: reg contherm rmtherm   ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic  if electionyear == 2008 [aweight=nationalweight]
eststo model2011controls: reg contherm rmtherm   ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic  if electionyear == 2011 [aweight=nationalweight]
eststo model2015controlsphone: reg contherm rmtherm ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic    if electionyear == 2015 & mode==0 [aweight=nationalweight] 
eststo model2015controlsonline: reg contherm rmtherm ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic    if electionyear == 2015  & mode==1 [aweight=nationalweight]
eststo model2019controlsonline: reg contherm rmtherm ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic    if electionyear == 2019 & mode==1 [aweight=nationalweight] 

suest  model1988controls model1993controls model1997controls  model2004controls model2006controls model2008controls model2011controls model2015controlsphone model2015controlsonline model2019controlsonline

test [model1988controls_mean ]rmtherm=[model2019controlsonline_mean  ]rmtherm
test [model1993controls_mean ]rmtherm=[model2019controlsonline_mean  ]rmtherm
test [model1997controls_mean ]rmtherm=[model2019controlsonline_mean  ]rmtherm
test [model2004controls_mean ]rmtherm=[model2019controlsonline_mean  ]rmtherm
test [model2006controls_mean ]rmtherm=[model2019controlsonline_mean  ]rmtherm
test [model2008controls_mean ]rmtherm=[model2019controlsonline_mean  ]rmtherm
test [model2011controls_mean ]rmtherm=[model2019controlsonline_mean  ]rmtherm
test [model2015controlsphone_mean]rmtherm=[model2019controlsonline_mean  ]rmtherm
test [model2015controlsonline_mean]rmtherm=[model2019controlsonline_mean ]rmtherm
  
  
eststo model2015phone: reg contherm rmDoMore   if electionyear == 2015 & mode==0 [pweight=nationalweight]
eststo model2015online: reg contherm rmDoMore   if electionyear == 2015 & mode==1 [pweight=nationalweight]
eststo model2019phone: reg contherm rmDoMore   if electionyear == 2019 & mode==0 [pweight=nationalweight]
eststo model2019online: reg contherm rmDoMore   if electionyear == 2019 & mode==1 [pweight=nationalweight]

eststo model2015phonecontrols: reg contherm rmDoMore   ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic  if electionyear == 2015 & mode==0 [aweight=nationalweight]
eststo model2015onlinecontrols: reg contherm rmDoMore   ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic  if electionyear == 2015 & mode==1 [aweight=nationalweight]
eststo model2019phonecontrols: reg contherm rmDoMore   ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic  if electionyear == 2019 & mode==0 [aweight=nationalweight]
eststo model2019onlinecontrols: reg contherm rmDoMore   ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic  if electionyear == 2019 & mode==1 [aweight=nationalweight]
eststo model2008controls: reg contherm rmDoMore   ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic  if electionyear == 2008  [aweight=nationalweight]
    
suest  model2015phonecontrols model2015onlinecontrols model2019phonecontrols model2019onlinecontrols model2008controls

test [model2015onlinecontrols_mean ]rmDoMore=[model2019onlinecontrols_mean ]rmDoMore
test [model2015onlinecontrols_mean ]rmDoMore=[model2019phonecontrols_mean ]rmDoMore
test [model2015phonecontrols_mean ]rmDoMore=[model2019onlinecontrols_mean ]rmDoMore
test [model2015phonecontrols_mean ]rmDoMore=[model2019phonecontrols_mean ]rmDoMore
test [model2008controls_mean ]rmDoMore=[model2019phonecontrols_mean ]rmDoMore
test [model2008controls_mean ]rmDoMore=[model2019onlinecontrols_mean ]rmDoMore

/*
I have also check this using the DoMore variable rather than racial therm. Results show that 
2019 phone/2015 phone p=.61
2019 online/2015 phone p=.19
2019 online/2015 online p=.08
2019 phone/2015 phone p=.72
*/

///////////////////////////////////////// Figure 4A Liberal Therm and Racial Therm

eststo clear
eststo model1988: reg libtherm rmtherm   if electionyear == 1988 [pweight=nationalweight]
eststo model1993: reg libtherm rmtherm  if electionyear == 1993 [pweight=nationalweight]
eststo model1997: reg libtherm rmtherm   if electionyear == 1997 [pweight=nationalweight]
eststo model2004: reg libtherm rmtherm   if electionyear == 2004 [pweight=nationalweight]
eststo model2006: reg libtherm rmtherm   if electionyear == 2006 [pweight=nationalweight]
eststo model2008: reg libtherm rmtherm   if electionyear == 2008 [pweight=nationalweight]
eststo model2011: reg libtherm rmtherm   if electionyear == 2011 [pweight=nationalweight]
eststo model2015phone: reg libtherm rmtherm   if electionyear == 2015 & mode==0 [pweight=nationalweight] 
eststo model2015online: reg libtherm rmtherm   if electionyear == 2015  & mode==1 [pweight=nationalweight]
eststo model2019online: reg libtherm rmtherm   if electionyear == 2019 & mode==1 [pweight=nationalweight] 


coefplot  model1988 model1993 model1997  model2004 model2006 model2008 model2011 model2015online model2015phone model2019online   ///
, nodraw drop(_cons) vertical keep (rmtherm) asequation swapnames legend(off)   scheme (plottig)  title("Bivariate") ytitle("LPC / Racial Therm Coef") ///
xlabel(.55 "1988" 1.65 "1993" 2.75 "1997" 3.85 "2004" 4.95 "2006" 6.05 "2008" 7.15 "2011" 8.25 "2015 Phone" 9.35 "2015 Online" 10.45 "2019 Online"  , angle(45))
graph save Graph "BivariateLiberal.gph", replace

esttab using "Table6A - RacialTherm Bivariate Lib.rtf", replace se r2 ar2  b(2) compress modelwidth(5) nobaselevels ///
label varlabels(rmtherm RacialTherm   _cons Intercept) ///
title(Table 6A: Bivariate Models (Liberal Therm DV)) nonumbers ///
mtitles("1988" "1993"	"1997"	"2004" "2006"	"2008"	"2011"	"2015 Phone" "2015 Online" "2019 Online") 


eststo clear
eststo model1988controls: reg libtherm rmtherm   ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic   if electionyear == 1988 [pweight=nationalweight]
eststo model1993controls: reg libtherm rmtherm   ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic  if electionyear == 1993 [pweight=nationalweight]
eststo model1997controls: reg libtherm rmtherm   ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic  if electionyear == 1997 [pweight=nationalweight]
eststo model2004controls: reg libtherm rmtherm   ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic  if electionyear == 2004 [pweight=nationalweight]
eststo model2006controls: reg libtherm rmtherm   ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic  if electionyear == 2006 [pweight=nationalweight]
eststo model2008controls: reg libtherm rmtherm   ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic   if electionyear == 2008 [pweight=nationalweight]
eststo model2011controls: reg libtherm rmtherm   ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic   if electionyear == 2011 [pweight=nationalweight]
eststo model2015controlsphone: reg libtherm rmtherm ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic    if electionyear == 2015 & mode==0 [pweight=nationalweight] 
eststo model2015controlsonline: reg libtherm rmtherm ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic    if electionyear == 2015  & mode==1 [pweight=nationalweight]
eststo model2019controlsonline: reg libtherm rmtherm ftherm   age educ income woman i.partisanship i.prov i.ces_ethnic    if electionyear == 2019 & mode==1 [pweight=nationalweight] 

coefplot    model1988controls model1993controls model1997controls  model2004controls model2006controls model2008controls model2011controls         model2015controlsphone model2015controlsonline  model2019controlsonline  ///
, nodraw drop(_cons) vertical keep (rmtherm) asequation swapnames legend(off)   scheme (plottig)   title("Multivariate") ytitle("LPC / Racial Therm Coef")  ///
xlabel(.55 "1988" 1.65 "1993" 2.75 "1997" 3.85 "2004" 4.95 "2006" 6.05 "2008" 7.15 "2011" 8.25 "2015 Phone" 9.35 "2015 Online" 10.45 "2019 Online"  , angle(45))
graph save Graph "ControlsLiberal.gph", replace


graph combine "BivariateLiberal.gph" "ControlsLiberal.gph",  imargin(zero) scheme(plottig)  commonscheme cols(1) ysize(6)  play("Figure 4 - racial therm and ndp.grec") 
graph save  "Figure 4A - Racial Spillover to the Party, Liberal", replace
graph export "Figure 4A - Racial Spillover to the Party, Liberal.pdf", replace

esttab using "Table7A - RacialTherm Multivariate Lib.rtf", replace se r2 ar2  b(2) compress modelwidth(5) nobaselevels ///
label order(rmtherm ftherm age educ income woman 1.partisanship 2.partisanship 3.partisanship 4.partisanship 5.partisanship  ///
 1.prov 2.prov 3.prov 4.prov 5.prov 6.prov 7.prov 8.prov 9.prov 10.prov ///
 1.ces_ethnic 2.ces_ethnic 3.ces_ethnic 4.ces_ethnic 5.ces_ethnic 6.ces_ethnic 7.ces_ethnic _cons) ///
varlabels(rmtherm RacialTherm ftherm FemTherm age Age educ Education income Income woman Woman  ///
1.partisanship Conservative 2.partisanship Liberal 3.partisanship NDP 4.partisanship BQ 5.partisanship OtherPID  _cons Intercept) ///
title(Table 7A: Multivariate Models (Liberal Therm DV)) nonumbers ///
mtitles("1988" "1993"	"1997"	"2004" "2006"	"2008"	"2011"	"2015 Phone"	"2015 Online" "2019 Online") 


///////////////////////////////////////// Missing Data analysis

gen rmthermmissing=.
replace rmthermmissing=0 if rmtherm==.
replace rmthermmissing=1 if rmtherm!=.

mean rmDoMore  [pweight=nationalweight] if electionyear==2019 & mode==1 & rmthermmissing==0
mean rmDoMore  [pweight=nationalweight] if electionyear==2019 & mode==1 & rmthermmissing==1
reg rmDoMore rmthermmissing [pweight=nationalweight] if electionyear==2019 & mode==1

mean ndptherm  [pweight=nationalweight] if electionyear==2019 & mode==1 & rmthermmissing==0
mean ndptherm  [pweight=nationalweight] if electionyear==2019 & mode==1 & rmthermmissing==1
reg ndptherm rmthermmissing [pweight=nationalweight] if electionyear==2019 & mode==1



///////////////////////////////////////// Table 10A Testing Differences in Sample Composition

eststo clear
eststo samplebivariate: reg ndptherm c.rmtherm##ib2020.electionyearmode  c.age c.rmtherm#c.age c.educ c.rmtherm#c.educ c.income  c.rmtherm#c.income woman c.rmtherm#woman i.prov c.rmtherm#i.prov i.ces_ethnic c.rmtherm#i.ces_ethnic if electionyearmode > 2011  , noomitted 
eststo samplemultivariate: reg ndptherm c.rmtherm##ib2020.electionyearmode  c.age c.rmtherm#c.age c.educ c.rmtherm#c.educ c.income  c.rmtherm#c.income woman c.rmtherm#i.woman i.prov c.rmtherm#i.prov i.ces_ethnic c.rmtherm#i.ces_ethnic ftherm i.partisanship if electionyearmode > 2011  , noomitted 


esttab using "Table 10A  - Sample Composition Models.rtf", replace se r2 ar2  b(2) compress modelwidth(5) nobaselevels ///
label order(rmtherm) ///
varlabels(rmtherm RacialTherm ftherm FemTherm age Age c.rmtherm#c.age RacialTherm*Age ///
educ Education c.rmtherm#c.educ RacialTherm*Education income Income c.rmtherm#c.income RacialTherm*Income /// 
woman Woman  1.woman#c.rmtherm RacialTherm*Woman ///
2015.electionyearmode 2015Phone 2015.electionyearmode#c.rmtherm RacialTherm*2015Phone 2016.electionyearmode 2015Online 2016.electionyearmode#c.rmtherm RacialTherm*2015Online /// 
1.ces_ethnic SouthAsian 1.ces_ethnic#c.rmtherm RacialTherm*SouthAsian 2.ces_ethnic EastSouthEastAsian 2.ces_ethnic#c.rmtherm RacialTherm*EastSouthEastAsian ///
3.ces_ethnic Black 3.ces_ethnic#c.rmtherm RacialTherm*Black 4.ces_ethnic LatinAmerican 4.ces_ethnic#c.rmtherm RacialTherm*LatinAmerican ///
5.ces_ethnic WestAsianArab 5.ces_ethnic#c.rmtherm RacialTherm*WestAsianArab 6.ces_ethnic Indigenous 6.ces_ethnic#c.rmtherm RacialTherm*Indigenous ///
7.ces_ethnic Other 7.ces_ethnic#c.rmtherm RacialTherm*Other ///
1.prov#c.rmtherm RacialTherm*NL 2.prov#c.rmtherm RacialTherm*NS ///
3.prov#c.rmtherm RacialTherm*NB 4.prov#c.rmtherm RacialTherm*QC 5.prov#c.rmtherm RacialTherm*ON 6.prov#c.rmtherm RacialTherm*MB ///
7.prov#c.rmtherm RacialTherm*SK 8.prov#c.rmtherm RacialTherm*AB 9.prov#c.rmtherm RacialTherm*BC  ///
1.partisanship Conservative 2.partisanship Liberal 3.partisanship NDP 4.partisanship BQ 5.partisanship OtherPID  _cons Intercept ) ///
title(Table 10A  - Sample Composition Models) nonumbers ///
mtitles("Mode 1" "Model 2, additional controls") 



///////////////////////////////////////// Figure 8A Before and After Blackface
eststo clear
eststo model2019before: reg ndptherm rmtherm   if electionyear == 2019 & afterblackface==0 [pweight=nationalweight]
eststo model2019after: reg ndptherm rmtherm   if electionyear == 2019 & afterblackface>0 [pweight=nationalweight]
eststo model2019beforeinteraction: reg ndptherm c.rmtherm##afterblackface   if electionyear == 2019  [pweight=nationalweight]

eststo model2019beforeinteraction: reg ndptherm c.rmtherm##afterblackface ftherm   age educ income woman i.partisanship i.prov  if electionyear == 2019  [pweight=nationalweight]


coefplot   model2019before model2019after ///
, keep (rmtherm) vertical legend(off)  xlabel (.84 "Before" 1.16 "After")  ylabel(0(.05).4)  ytitle("NDP / Racial Therm Coef") scheme (plottig) 

graph save Graph "Figure 7A - Before and After BlackFace.gph", replace

esttab using "Table 11A Blackface.rtf", replace se r2 ar2  b(2) compress modelwidth(5) nobaselevels ///
label varlabels(rmtherm RacialTherm 1.afterblackface AfterBlackface 1.afterblackface#c.rmtherm RacialTherm*AfterBlackface  _cons Intercept) ///
title(Table 11A: Before and After the Trudeau Blackface Controversy) nonumbers ///
mtitles("Before Bivariate"	"After Bivariate"	"Interaction") 

